package com.gms.service.eventmanager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gms.entity.event.Event;
import com.gms.entity.event.Referee;
import com.gms.mapper.eventmanager.RefereeMapper;
import com.gms.service.eventmanager.RefereeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *赛事-裁判
 *Service层
 *
 */
@Service
public class RefereeServiceImpl extends ServiceImpl<RefereeMapper, Referee> implements RefereeService {

    @Autowired
    RefereeMapper refereeMapper;


    //裁判插入
    @Override
    public void insertReferee(Referee referee){
        refereeMapper.insert(referee);
    }

    //裁判删除
    @Override
    public void deleteReferee(String referee_id){
        refereeMapper.deleteById(referee_id);
    }

    //裁判跟新
    @Override
    public void updateReferee(Referee referee){
        refereeMapper.updateById(referee);
    }

    //裁判查询
    @Override
    public Referee queryReferee(String referee_id){
        QueryWrapper<Referee> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("referee_id",referee_id);
        return refereeMapper.selectOne(queryWrapper);
    }

    @Override
    public Page<Referee> queryAll(Integer PageNum){
        Page<Referee> page=new Page(PageNum,8);
        return refereeMapper.selectPage(page,null);
    }

    @Override
    public List<Referee> queryAll(){
        return refereeMapper.selectList(null);
    }

    @Override
    public String queryName(String RefereeId){
        Referee referee = refereeMapper.selectById(RefereeId);
        return referee.getRefereeName();
    }

    @Override
    public Page<Referee> queryReferee_id_name(Integer PageNum,String referee_id,String referee_name) {
        Page<Referee> page=new Page(PageNum, 8);
        Map<String,Object> map = new HashMap<>();
        QueryWrapper<Referee> queryWrapper = new QueryWrapper<>();
        map.put("referee_id",referee_id);
        queryWrapper.allEq(map,false);
        queryWrapper.like("referee_name",referee_name);
        return refereeMapper.selectPage(page,queryWrapper);
    }


}
